package com.b2bpsssm.controller.sysmanage;/**
 * @author JunYu
 * @create 2022-08-12--10:08
 */

import com.b2bpsssm.common.R;
import com.b2bpsssm.utils.JwtUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.UUID;

/**
 * @program: B2BPSSMSystem
 * @description: 用于登录的控制器：不需要权限即可访问，登录成功后会返回token，要求后续所有请求需要在请求头中
 * 带上token，否则会视为未登录。
 * @author: JunYu
 * @create: 2022-08-12 10:08
 **/
@EnableSwagger2
@Controller
@Api(value = "用户登录模块", tags = "用户登录模块api")
public class LoginController {
    //登录，登录成功后会返回token
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "登录接口", notes = "验证用户的用户名和密码", httpMethod = "post", response = R.class)
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "user_email", value = "用户邮箱(账号)", paramType = "query", dataType = "String", required = true),
                    @ApiImplicitParam(name = "password", value = "密码", paramType = "query", dataType = "String", required = true)
            }
    )
    public R login(@RequestParam(value = "user_email", required = true) String user_email, @RequestParam(value = "password", required = true) String password) {
        R r = new R();
        r.setMassage("登录成功");
        r.setCode(200);
        String jwtToken = JwtUtils.createJwt(UUID.randomUUID().toString(), "JWT_TEST", JwtUtils.generalSubject(user_email), JwtUtils.TTMILLIS);
        r.setData(jwtToken);
        return r;
    }
}
//@Api(value = "",tags = "")
//@ApiOperation(value = "/",notes = "",httpMethod = "", response = )
//@ApiImplicitParams(
//        {
//                @ApiImplicitParam(name = "",value = "",paramType = "",dataType = "",required = true),
//                @ApiImplicitParam(name = "",value = "",paramType = "",dataType = "",required = true)
//        }
//)